//
//  BIZCCLiveNavBarLeftButton.m
//  biz
//
//  Created by zhangfuwei on 2017/3/29.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZCCLiveNavBarLeftButton.h"

@implementation BIZUserNameAvatarModel

@end


@implementation BIZCCLiveNavBarLeftButton{
    UIImageView     *_backGroudImgV;
    UIImageView     *_avatarImgV;
    UILabel         *_nameLab;
    NSString *_name;
    NSString *_avatarStr;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        [self loadUI];
    }
    return self;
}

- (void)loadUI {
    
    _backGroudImgV = [[UIImageView alloc] init];
    [_backGroudImgV setImage:[UIImage imageNamed:@"ccLiveRoom_buttonBg"]];
    _backGroudImgV.layer.cornerRadius = 15;
    _backGroudImgV.clipsToBounds = YES;
    
    _avatarImgV = [[UIImageView alloc] init];
    _avatarImgV.layer.cornerRadius = 15;
    _avatarImgV.clipsToBounds = YES;
    
    _nameLab = [[UILabel alloc] init];
    _nameLab.font = CHINESE_SYSTEM(15);
    [self addSubview:_backGroudImgV];
    [self insertSubview:_avatarImgV aboveSubview:_backGroudImgV];
    [self insertSubview:_nameLab aboveSubview:_backGroudImgV];
    
}

-(void)layoutSubviews {
    [super layoutSubviews];

    [_backGroudImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [_avatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.equalTo(@30);
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(10);
    }];
    
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_avatarImgV.mas_right).offset(5);
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(-10);
        make.height.equalTo(@20);
    }];
    
}

-(void)setUserM:(BIZUserNameAvatarModel *)userM {
    _userM = userM;
    
    [_avatarImgV sd_setImageWithURL:[NSURL URLWithString:userM.avatar] placeholderImage:[UIImage imageNamed:@"default-head"]];
    _nameLab.text = userM.name?:@"李贺";
    [self layoutIfNeeded];

}

- (void)setRoomName:(NSString *)roomName {
    _roomName = roomName;
    _nameLab.text = roomName;
}
@end
